
library(foreign)

# ======================================================================================
# =                        Figure 7                                                    =
# ======================================================================================

dat <- read.csv("figure7_data.csv")

attach(dat)

y.axis <- length(var):1

postscript(file="Figure7.eps", pointsize=10, width=6.4, height=5.1, 
	horizontal = FALSE, onefile = FALSE, paper = "special")

par(mar=c(3,3,1,1))

adjust <- .25

layout(matrix(c(2,1),1,2), widths = c(1, 5.5)) 
plot(coef1, y.axis, type="n",axes=F, xlab = "", ylab = "", pch = 19, cex = 1.3,
      xlim = c(-.4,.75), ylim = c(min(y.axis-adjust), max(y.axis+adjust)))
axis(1,at=seq(-.4,.75,by=.1),cex.axis = .9)
axis(2, at = y.axis, label = var, las = 1, tick = T, cex.axis =1.1)
abline(h = y.axis, lty = 2, lwd = 1, col = "grey")
abline(v=0,col="gray40")

points(coef1, y.axis, pch = 19, cex = 1.3, col = "black")
segments(coef1-1.96*se1,y.axis,coef1+1.96*se1, y.axis,lwd=1.9)

segments(re-1.96*re.se,y.axis+adjust,re+1.96*re.se,y.axis+adjust,col="black",lwd=1.9)
points(re, y.axis+adjust, pch = 21, cex = 1.3, col = "black",bg="lightgrey")

segments(fe-1.96*fe.se, y.axis-adjust, fe+1.96*fe.se, y.axis-adjust, col="black",lwd=1.9)
points(fe, y.axis-adjust, pch = 22, cex = 1.3, col = "black", bg="lightgrey")

legend(x=.28,y=2.2,c("Factor scores OLS", "Multilevel IRT", "Factor scores HLM"),
       pch=c(21,19,22), pt.bg=c("lightgrey", "black","lightgrey"),
		 pt.cex=1.3, bg="white",box.lwd=.8)

dev.off()


